﻿Imports System.Collections.ObjectModel

''' <summary>
''' Represents the structure of an NFA that manage serveral states and edges
''' </summary>
Public Class NFAModel
    Private m_states As List(Of NFAState)

    Sub New()
        m_states = New List(Of NFAState)
    End Sub

    Public ReadOnly Property States() As ReadOnlyCollection(Of NFAState)
        Get
            Return m_states.AsReadOnly()
        End Get
    End Property

    Private m_tail As NFAState
    Public Property TailState As NFAState
        Get
            Return m_tail
        End Get
        Friend Set(ByVal value As NFAState)
            m_tail = value
        End Set
    End Property

    Private m_entryEdge As NFAEdge
    Public Property EntryEdge As NFAEdge
        Get
            Return m_entryEdge
        End Get
        Friend Set(ByVal value As NFAEdge)
            m_entryEdge = value
        End Set
    End Property

    Friend Sub AddState(ByVal state As NFAState)
        m_states.Add(state)
        state.Index = m_states.Count - 1
    End Sub

    Friend Sub AddStates(ByVal states As IEnumerable(Of NFAState))
        For Each s In states
            AddState(s)
        Next
    End Sub

    Friend Sub SetEdgePriority(ByVal priority As Integer)
        For Each state In m_states
            For Each edge In state.OutEdges
                edge.Priority = priority
            Next
        Next

        EntryEdge.Priority = priority
    End Sub
End Class
